import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
import fileViewRouter from './modules/FileView'

import upmsRouter from './modules/upms'
import monitoringRourer from './modules/Monitoring'
import docsRouter from './modules/Docs'
import thirdRouter from './modules/third'
import businessRouter from './modules/business'
export const constantRoutes = [
  {
    path: '/sso',
    name: 'sso',
    component: () => import('@/layout/Layout1'),
    redirect: '/login',
    hidden: true,
    children: [{
      path: '/login',
      name: 'login',
      meta: { title: '登录' },
      component: () => import('@/views/sso/login')
    }, {
      path: '/invite/:code',
      name: 'invite',
      component: () => import('@/views/upms/user/personalData/invite'),
      hidden: true
    }, {
      path: '/password',
      name: 'password',
      meta: { title: '找回密码' },
      component: () => import('@/views/sso/password')
    }, {
      path: '/register',
      name: 'register',
      meta: { title: '注册' },
      component: () => import('@/views/sso/register')
    }, {
      path: '/company',
      name: 'company',
      meta: { title: '创建企业' },
      component: () => import('@/views/sso/company')
    }, {
      path: '/updateRecord',
      name: 'updateRecord',
      meta: { title: '更新记录' },
      component: () => import('@/views/sso/updateRecord')
    }]
  }, {
    path: '/legaAgreement/:code',
    name: 'legaAgreement',
    meta: { title: '隐私服务协议内容' },
    component: () => import('@/views/sso/legaAgreement')
  }, {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true
  }, {
    path: '/noPermission',
    name: 'noPermission',
    component: () => import('@/views/noPermission'),
    hidden: true
  }, {
    path: '/app/h5/download/:code',
    name: 'appH5Download',
    component: () => import('@/views/upms/systemSetting/app/h5Download'),
    hidden: true
  }, {
    path: '/lockScreen',
    name: 'lockScreen',
    component: () => import('@/views/lock/index'),
    hidden: true
  },
  fileViewRouter,
  {
    path: '/helpDocs',
    name: 'helpDocs',
    component: () => import('@/views/upms/systemSetting/help/helpDocsLayout'),
    redirect: '/helpDocs/index',
    hidden: true,
    children: [{
      path: 'index',
      name: 'helpDocsIndex',
      component: () => import('@/views/upms/systemSetting/help/helpDocs')
    }]
  }, {
    path: '/common',
    name: 'common',
    component: Layout,
    redirect: '/common/personalData',
    hidden: true,
    children: [{
      path: 'personalData',
      name: 'personalData',
      component: () => import('@/views/upms/user/personalData/index'),
      meta: { title: '个人资料', icon: 'dashboard' }
    }]
  }, {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    meta: { title: '工作台', icon: 'menuHome' },
    children: [{
      path: 'dashboard',
      name: 'DashboardIndex',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'menuHome' }
    }]
  }, {
    path: '/mailList',
    component: Layout,
    redirect: '/mailList',
    name: 'mailList',
    meta: { title: '通讯录', icon: 'menuHome' },
    children: [{
      path: '',
      name: 'mailListIndex',
      component: () => import('@/views/upms/user/user/mailList'),
      meta: { title: '通讯录', icon: 'menuHome' }
    }]
  }, {
    path: '/example',
    name: 'example',
    component: Layout,
    redirect: '/example/map',
    meta: { title: '示例', icon: 'menuHome' },
    children: [{
      path: 'map',
      name: 'exampleMap',
      meta: { title: '地图下钻', icon: 'menuHome' },
      component: () => import('@/views/example/map')
    }, {
      path: 'processDesigner',
      name: 'exampleProcessDesigner',
      meta: { title: '工作流', icon: 'menuHome' },
      component: () => import('@/views/example/processDesigner')
    }, {
      path: 'testExample',
      name: 'testExample',
      meta: { title: '示例', icon: 'menuMessage' },
      component: () => import('@/views/business/testExample')
    }, {
      path: 'localCamera',
      name: 'localCamera',
      meta: { title: '本地摄像头', icon: 'menuMessage' },
      component: () => import('@/views/example/localCamera')
    }, {
      path: 'icon',
      name: 'icon',
      meta: { title: '图标库', icon: 'menuMessage' },
      component: () => import('@/views/example/icon')
    }, {
      path: 'upload',
      name: 'upload',
      meta: { title: '上传示例', icon: 'menuMessage' },
      component: () => import('@/views/example/upload')
    }]
  }, {
    path: '/message',
    component: Layout,
    redirect: '/message',
    name: 'message',
    meta: { title: '我的消息', icon: 'menuMessage' },
    children: [{
      path: '',
      name: 'messageIndex',
      meta: { title: '我的消息', icon: 'menuMessage' },
      component: () => import('@/views/upms/user/msg')
    }]
  },
  businessRouter,
  {
    path: '/application',
    component: Layout,
    redirect: '/application',
    name: 'application',
    meta: { title: '应用', icon: 'menuLog' },
    children: [{
      path: '',
      name: 'applicationIndex',
      meta: { title: '应用', icon: 'menuMessage' },
      component: () => import('@/views/application/index')
    }]
  },
  thirdRouter,
  docsRouter,
  upmsRouter,
  monitoringRourer,
  {
    path: '/securityLog',
    component: Layout,
    redirect: '/systemLog',
    name: 'securityLog',
    meta: { title: '安全日志', icon: 'menuLog' },
    children: [{
      path: '',
      name: 'securityLogIndex',
      meta: { title: '安全日志', icon: 'menuMessage' },
      component: () => import('@/views/upms/systemSetting/log/index')
    }]
  }
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
